(function (){

    $(".back").click(function () {
        $("body,html").animate({ scrollTop: 0 }, 500)
        console.log("aaa")
    })
    
    $.ajax({
        type: "GET",
        url: "http://chst.vip:1234/api/getcategorytitle",
        data: {}
    }).then(res => {
        let html = "";
        data = res.result;
        data.forEach(function (item) {
            html += `
            <li>
                <p>${item.title}</p>
                <div></div>
            </li>
            <div class="container"></div>
            `
        })
        html+=""
        $(".list").html(html);
        $(".list").children("li").click(function(){
             if($(this).next().css("max-height")!="0px"){
                $(this).next().css("max-height","0px");
             }else{
                $(this).next().css("max-height","6rem");
                $(this).next().siblings("div").css("max-height","0rem")
             }
        })
        
    })
            let length=[];
    function fn(x) { 
        $.ajax({
            type: "GET",
            url: "http://chst.vip:1234/api/getcategory",
            data: {titleid:x}
        }).then(res=>{
            let arr=res.result;
            let html="";
            length[x]=arr.length
            arr.forEach(function(item){
                html+=`
                    <div>${item.category}</div>
                `
            })
            $(".container:eq("+x+")").html(html);

        })
     }
     for(var i=0;i<8;i++){
         fn(i);
     }
    
     
    
    
    })()

    function scrollHandler() {
        const height = $(this).scrollTop()
        if(height>=10) {
            $('.gotop').fadeIn(500)
        }else{
            $('.gotop').fadeOut(500)
        }
    }

    scrollHandler()
    $(window).scroll(scrollHandler)

    $('.gotop').click(function () {
      $('body, html').animate({ scrollTop: 0 }, 1000)
    })